package com.ymatou.iapi.falcon.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.falcon.parameter.SaveSingleBean;
import com.ymatou.iapi.falcon.service.SaveSingleCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

import oracle.net.aso.s;
/**
*保存单个异常
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SaveSingle{
	private static SaveSingleBean savesingleBean;
	private static SaveSingleCall savesingleCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("保存单个异常");
	}

	@Before
	public void caseUp() {
		savesingleBean=new SaveSingleBean();
		savesingleCall=new SaveSingleCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(savesingleCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveSingle_001() {
		Logger.start(true,"保存单个异常");
		try {
			 java.util.Random r=new java.util.Random(10000); 
			//TODO 补全case代码     
			savesingleBean.setAppId("disconfadmin.ymatou.cn");
			savesingleBean.setReqUrl("http://disconfadmin.ymatou.cn/warmup");
			savesingleBean.setReqForm("{id:1}");
			savesingleBean.setErrorLevel(2);
			savesingleBean.setMethodName("getId");
			savesingleBean.setAssemblyName("NiceToMeetYou");
			savesingleBean.setTitle("http://disconfadmin.ymatou.cn/");
			savesingleBean.setMessage("<html><body><table border=\"1\"><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table></body></html>");
			savesingleBean.setExceptionName("Null Exception");        
			savesingleBean.setHeader("headder");
			savesingleBean.setStackTrace("exception:java.lang.RuntimeException: java.lang.RuntimeException: org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\n; message exceptions (1) are:\r\nFailed message 1: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\n|sendEmail,mailRecordId=be637256b5d947169dfd146611ff4b8f,error:java.lang.RuntimeException: org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\n; message exceptions (1) are:\r\nFailed message 1: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\n\r\njava.lang.RuntimeException: java.lang.RuntimeException: org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\n; message exceptions (1) are:\r\nFailed message 1: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\n\r\nat com.ymatou.emailservice.domain.service.EmailService.sendEmail(EmailService.java:292)\r\nat com.ymatou.emailservice.domain.service.EmailService.lambda$sendEmail$0(EmailService.java:162)\r\nat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\r\nat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\r\nat java.lang.Thread.run(Thread.java:745)\r\nCaused by: java.lang.RuntimeException: org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\n; message exceptions (1) are:\r\nFailed message 1: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\nat com.ymatou.emailservice.domain.service.EmailService.sendEmail(EmailService.java:109)\r\nat com.ymatou.emailservice.domain.service.EmailService.localSend(EmailService.java:216)\r\nat com.ymatou.emailservice.domain.service.EmailService.sendEmail(EmailService.java:272)\r\n\r\n\r\n... 4 more\r\nCaused by: org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\n\r\n; message exceptions (1) are:\r\nFailed message 1: com.sun.mail.smtp.SMTPSendFailedException: 550 Connection frequency limited\r\n\r\nat org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:474)\r\nat org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345)\r\n\r\nat org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)\r\nat com.ymatou.emailservice.domain.service.EmailService.sendEmail(EmailService.java:107)\r\n\r\n... 6 more\r\n");
			savesingleBean.setAddTime(YMTDateUtil.getSysTime());
			savesingleBean.setMachineIp("172.16.102.13");
			
			for (int i = 0; i < 10; i++) {
				savesingleBean.setTitle("http://disconfadmin.ymatou.cn/"+i);
				savesingleBean.setMessage("<br/><B><br/>oMessage:<strong>dispatch-rmq.iapi.ymatou.com</strong></B>"+r.nextInt()+"<br/>");
				//savesingleBean.setMessage("Message:dispatch-rmq.iapi.ymatou.com"+r.nextInt()+"");

				savesingleCall.setData(savesingleBean);
				savesingleCall.callService();
				
				Thread.sleep(1000);
			}   
				
			
					
//			savesingleBean.setAppId("couponservice.iapi.ymatou.com");
//			savesingleBean.setReqUrl("http://couponservice.iapi.ymatou.com/warmup");
//			savesingleBean.setReqForm("{id:1}");
//			savesingleBean.setErrorLevel(2);
//			savesingleBean.setMethodName("getId");
//			savesingleBean.setAssemblyName("NiceToMeetYou");
//			savesingleBean.setTitle("couponservice.iapi.ymatou.com");
//			savesingleBean.setExceptionName("Null Exception");
//			savesingleBean.setHeader("headder");
//			savesingleBean.setStackTrace("eggfdrgkjhiwdhfueiwhduiwehfoiwfoewhfieuiwrhfueiwrhforuewhfueiwrh");
//			savesingleBean.setAddTime("2017-07-12 15:34:52");
//			savesingleBean.setMachineIp("172.16.102.12");
//			
//			for (int i = 0; i < 7; i++) {
//				savesingleBean.setMessage("couponservice.iapi.ymatou.com"+r.nextInt());
//				savesingleCall.setData(savesingleBean);
//
//				savesingleCall.callService();	
//			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveSingle_002() {
		Logger.start(true,"保存单个异常");
		try {
			 java.util.Random r=new java.util.Random(10000); 
			//TODO 补全case代码     
			savesingleBean.setAppId("disconfadmin.ymatou.cn");
			savesingleBean.setReqUrl("http://disconfadmin.ymatou.cn/warmup");
			savesingleBean.setReqForm("{id:1}");
			savesingleBean.setErrorLevel(2);
			savesingleBean.setMethodName("getId");
			savesingleBean.setAssemblyName("NiceToMeetYou");
			savesingleBean.setTitle("http://disconfadmin.ymatou.cn/");
			savesingleBean.setMessage("RPC,AppId:productstock.iapi.ymatou.com,ServiceClient,[RequestId]:e74c1facebe049d3bba7f904c39ed274,[RequestIndex]:1,ConsumerAppId:productstock.iapi.ymatou.com->ProviderAppId:proditem.iapi.ymatou.com (ApiName:api/Product/GetProductInfoByTradeIsolation,ApiPath:api/Product/GetProductInfoByTradeIsolation,Host:http://proditem.iapi.ymatou.com,HttpMethod:GET,parameterBuildType:UrlQueryString),ConsumerAppIp:10.11.21.20请求被中止: 操作超时。");
			savesingleBean.setExceptionName("Null Exception");        
			savesingleBean.setHeader("headder");
			savesingleBean.setStackTrace("dsfasfasfaesfdsfasfasfaesfdsfasfasfae\r\nsfdsfasfasfaesfdsfasfasfaesfdsfas\r\nfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesf\r\ndsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfa\nesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesf\ndsfasfasfaesfdsfasdsfasfas\nfaesfdsfasfasfaes\nfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfas\nfasfaesfdsfasfasfaesfdsfasfasfaesfds\nfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfa\nsfaesfdsfasfasfaesfdsfasf\nasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsf\nasfasfaesfdsfasfasfaesfdsfasfasfae\r\nsfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfa\r\nsfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfasfasfaesfdsfas");
			savesingleBean.setAddTime(YMTDateUtil.getSysTime());
			savesingleBean.setMachineIp("172.16.102.13");
			
			for(int i=0;i<12;i++)
			{
				savesingleCall.setData(savesingleBean);
				savesingleCall.callService();  
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}